let $dlg = (function(){
  let html = `<div class="dlg-lookup-bg">
    <div class="dlg-lookup">
      <div class="titlebar">
        <p class="title">查找</p>
        <span class="close-btn">×</span>
      </div>
      <div class="main">
        <label>查找内容(<u>N</u>)：</label>
        <input class="lookup-text" type="text">
        <button class="lookup-next" disabled>查找下一个(<u>F</u>)</button>
        <br>
        <input class="lookup-cancel" type="button" value="取消">
        <div class="demand">
          <div class="demand-checkbox">
            <input type="checkbox" class="case">区分大小写(<u>C</u>)
            <br><br>
            <input type="checkbox" class="loop">循环(<u>R</u>)
          </div>
          <fieldset class="direction">
            <legend>方向</legend>
            <input class="up" type="radio" name="direction" value='up'>向上(<u>U</u>)
            <input class="down" type="radio" name="direction" value='down' checked="true">向下(<u>D</u>)
          </fieldset>
        </div>
      </div>
    </div>
  </div>`;
  let $body = $('body');

  function show(config){  
    $body.append(html);
    let $lookup = $('.dlg-lookup-bg');
    let $close = $('.close-btn');
    let $cancel = $('.lookup-cancel');
    let $text = $('.lookup-text');
    let $next = $('.lookup-next');

    $text.get(0).focus();

    // 查找按钮是否禁用
    $text.bind('input propertychange',function(){
      if($text.val().length !== 0){
        $next.removeAttr('disabled');
      }else{
        $next.attr('disabled', 'disabled');
      }
    });

    // 查找下一个
    $next.click(() => {
      let caseState = $('.case').get(0).checked === true ? '是' : '否';
      let loopState = $('.loop').get(0).checked === true ? '是' : '否';
      let direction = $('input[name="direction"]:checked').val() === 'up' ? '向上' : '向下';
        console.log(`查找内容:    ${$text.val()}`);
        console.log(`区分大小写： ${caseState}`);
        console.log(`循环：       ${loopState}`);
        console.log(`查找方向：   ${direction}`);
    });

    // 关闭对话框
    $close.click(()=>{
      $lookup.remove();
    });
    $cancel.click(()=>{
      $lookup.remove();
    });
  }

  return  { show };

})()
